﻿using ArbabTravelsERP.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Web;

namespace ArbabTravelsERP.DAL
{
    public class VisaDAL
    {
        DataUtility du = new DataUtility();

        public DataTable InsertVisaDetails(VisaModel visa)
        {
            try
            {
                if (visa.ISSUE_DATE == null)
                {
                    visa.ISSUE_DATE = null;
                }
                else
                {
                    visa.ISSUE_DATE = DateTime.ParseExact(visa.ISSUE_DATE, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString();
                }

                if (visa.EXPIRY_DATE == null)
                {
                    visa.EXPIRY_DATE = null;
                }
                else
                {
                    visa.EXPIRY_DATE = DateTime.ParseExact(visa.EXPIRY_DATE, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString();
                }

                if (visa.RECIEVED_DATE== null)
                {
                    visa.RECIEVED_DATE = null;
                }
                else
                {
                    visa.RECIEVED_DATE = DateTime.ParseExact(visa.RECIEVED_DATE, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString();
                }

                SqlParameter[] param = new SqlParameter[12];
                SqlParameter REGISTRATION_NO = new SqlParameter("@REGISTRATION_NUMBER", visa.REGISTRATION_NO);
                SqlParameter CIVILIAN_NUMBER = new SqlParameter("@CIVILIAN_NUMBER", visa.CIVILIAN_NUMBER);
                SqlParameter VISA_NUMBER = new SqlParameter("@VISA_NUMBER", visa.VISA_NUMBER);
                SqlParameter PURPOSE = new SqlParameter("@PURPOSE", visa.PURPOSE);
                SqlParameter PLACE_OF_ENDORSEMENT = new SqlParameter("@PLACE_OF_ENDORSEMENT", visa.PLACE_OF_ENDORSEMENT);
                SqlParameter ISSUE_DATE = new SqlParameter("@ISSUE_DATE", visa.ISSUE_DATE);
                SqlParameter EXPIRY_DATE = new SqlParameter("@EXPIRY_DATE", visa.EXPIRY_DATE);
                SqlParameter RECIEVED_DATE = new SqlParameter("@RECIEVED_DATE", visa.RECIEVED_DATE);
                SqlParameter FILE_PATH = new SqlParameter("@FILE_PATH", visa.FILE_PATH);
                SqlParameter REMARK = new SqlParameter("@REMARK", visa.REMARK);
                SqlParameter CREATED_BY = new SqlParameter("@CREATED_BY", "ambi");
                SqlParameter CONDITIONAL_OPERATOR = new SqlParameter("@CONDITIONAL_OPERATOR", "INSERT");
                
                param[0] = REGISTRATION_NO;
                param[1] = CIVILIAN_NUMBER;
                param[2] = VISA_NUMBER;
                param[3] = PURPOSE;
                param[4] = PLACE_OF_ENDORSEMENT;
                param[5] = ISSUE_DATE;
                param[6] = EXPIRY_DATE;
                param[7] = RECIEVED_DATE;
                param[8] = FILE_PATH;
                param[9] = REMARK;
                param[10] = CREATED_BY;
                param[11] = CONDITIONAL_OPERATOR;

                return du.ExecuteDataTable("StoredProcedure", "PROC_VISA_MASTER", param);
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}